package com.hpsk.aviator.module;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import com.googlecode.aviator.annotation.Function;
import com.googlecode.aviator.annotation.Import;
import com.googlecode.aviator.annotation.ImportScope;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author huangwang2832511019
 */
@Import(ns = "dateTime")
public class DateTimeModule {

    @Function(rename = "format")
    public static String format(String pattern) {
        if (ObjectUtil.isEmpty(pattern)) {
            pattern = DatePattern.CHINESE_DATE_PATTERN;
        }
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(pattern));
    }
    public static LocalDateTime parse(String dateTime) {
        return LocalDateTime.parse(dateTime,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}